/*------------------------------------------------------
                hou_elearningGEN beta v1.0
Author: xtrung.net@gmail.com
Write On: 04/27/2008
Create On:4/13/2012 11:23:00 AM
------------------------------------------------------*/
using hou_elearning.DataAccess.Base;
using hou_elearning.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;

namespace hou_elearning.DataAccess
{    
    public class DanhmuccauhoiDAL : SqlProvider<DanhmuccauhoiEntity>
    {
        static DanhmuccauhoiDAL()
        {
            InitReader();
        }
        protected static void InitReader()
        {
            getFromReader=delegate(SqlDataReader dr)
            {
                DanhmuccauhoiEntity entity = new DanhmuccauhoiEntity();
				entity.PK_iDanhmuccauhoiID = Int16.Parse("0"+dr["PK_iDanhmuccauhoiID"].ToString());
				entity.sTendanhmuccauhoi = dr["sTendanhmuccauhoi"].ToString();
                return entity;
            };
        }
        public static DanhmuccauhoiEntity GetOne(Int16 PK_iDanhmuccauhoiID)
        {
            string cmdName = "spDanhmuccauhoi_GetByPK";
            SqlParameter p = new SqlParameter("@PK_iDanhmuccauhoiID", PK_iDanhmuccauhoiID);
            DanhmuccauhoiEntity entity = GetOne(cmdName, p);
            return entity;
        }
        public static List<DanhmuccauhoiEntity> GetAll()
        {
            string cmdName = "spDanhmuccauhoi_Get";
            return GetList(cmdName);
        }
        
        public static int Add(DanhmuccauhoiEntity entity)
        {
            string cmdName = "spDanhmuccauhoi_Insert";
            return Run(cmdName,true,initParams(entity));

        }
        public static bool Edit(DanhmuccauhoiEntity entity)
        {
            string cmdName = "spDanhmuccauhoi_Update";
            return Run(cmdName,false,initParams(entity))>0;
        }
        public static bool Remove(Int16 PK_iDanhmuccauhoiID)
        {
            string cmdName = "spDanhmuccauhoi_Delete";
            SqlParameter p = new SqlParameter("@PK_iDanhmuccauhoiID", PK_iDanhmuccauhoiID);
            return Run(cmdName,false,p)>0;
        }
        #region private
        private static SqlParameter[] initParams(DanhmuccauhoiEntity entity)
        {
            SqlParameter[] p = new SqlParameter[2];
			p[0] = new SqlParameter("@PK_iDanhmuccauhoiID", entity.PK_iDanhmuccauhoiID);
			p[1] = new SqlParameter("@sTendanhmuccauhoi", entity.sTendanhmuccauhoi);
            return p;
        }
        #endregion
       
    }
}